package com.zzyl.nursing.controller.member;

import java.util.List;


import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.FamilyDto;
import com.zzyl.nursing.dto.FamilyElderQueryDto;
import com.zzyl.nursing.dto.QueryDeviceDataListCountDto;
import com.zzyl.nursing.vo.*;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 * 
 * @author laoYe
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public R login(@RequestBody UserLoginRequestDto dto) {
        LoginVo vo = familyMemberService.login(dto);
        return R.ok(vo);
    }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public R<List<QueryDeviceDataListCountVo>> queryDeviceDataListByDay(@Param("queryDeviceDataListCountDto") QueryDeviceDataListCountDto queryDeviceDataListCountDto){
        return R.ok(familyMemberService.queryDeviceDataListByDay(queryDeviceDataListCountDto));
    }

    /**
     * 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public R<List<QueryDeviceDataListCountVo>> queryDeviceDataListByWeek(@Param("queryDeviceDataListCountDto") QueryDeviceDataListCountDto queryDeviceDataListCountDto){
        return R.ok(familyMemberService.queryDeviceDataListByWeek(queryDeviceDataListCountDto));
    }



    /**
     * 1.1 绑定家人
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    @ApiParam(name = "familyDto", value = "老人信息")
    public R add(@RequestBody FamilyDto familyDto) {

            familyMemberService.add(familyDto);
            return R.ok();

    }
    /**
     * 1.2 查询家人列表
     */

    @GetMapping("/my")
    @ApiOperation(value = "获取客户老人家属关联列表")
    public R<List<FamilyMemberVo>> list() {

        List<FamilyMemberVo> list = familyMemberService.listByFamilyMemberId();

        return R.ok(list);
    }
    /**
     * 1.3 查看已绑定家人列表（分页查询）
     *  */
    @GetMapping("/list-by-page")
    @ApiOperation(value = "分页查询已绑定家人列表")
    public R<List<FamilyElderDetailVo>> page(FamilyElderQueryDto dto){
       List<FamilyElderDetailVo> pageInfo = familyMemberService.pageQuery(dto);
       return R.ok(pageInfo);

    }


    /**
     * 查询健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public R queryServiceProperties(@PathVariable String iotId){
        List<DeviceShadowDataVo> list = familyMemberService.queryServiceProperties(iotId);
        return R.ok(list);
    }





}
